<?php require_once ("header.php"); ?>
<?php 
	if ($ad_check==0 && $user_check==0){
		header ("Location:error.php?code=406");
	}
?>
<style type="text/css">
<!--
.style1 {
	font-size: 14px;
	font-weight: bold;
	color: #000000;
}
.style2 {color: #000000}
-->
</style>
<?php 
	if (isset($_POST['save'])) {
		$name=$_POST['nama'];
		$ic=$_POST['ic'];
		$course=$_POST['course'];
		$sem=$_POST['sem'];
		$class=$_POST['class'];
		$dep=$_POST['dep'];
		
		$sql_insert_data="UPDATE student SET stud_name='$name',stud_ic='$ic',stud_course='$course',stud_sem='$sem',class='$class',stud_deparment='$dep'
						WHERE stud_no='$id'";
		$insert_data=mysql_query($sql_insert_data);
		echo "<center>Update profile successful</center>";
	}	
		
	//GET ALL STUDENT DATA FROM DATABASE
	$sql_get_info="SELECT * FROM student WHERE stud_no='$id'";
	$get_info=mysql_query($sql_get_info);
	$info=mysql_fetch_assoc($get_info);
	
	
?>

<table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><p align="center" class="style1">STUDENT PROFILE </p>
	  <form method="POST" action="profile.php">
      <table width="603" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="229"><span class="style2">Name</span></td>
        <td width="10"><span class="style2">:</span></td>
        <td width="364"><input name="nama" type="text" id="nama" value="<?php echo $who; ?>" size="50" maxlength="255"></td>
      </tr>
      <tr>
        <td><span class="style2">Student Number </span></td>
        <td><span class="style2">:</span></td>
        <td><input name="id" type="text" id="id" value="<?php echo $info['stud_no']; ?>" readonly="1"></td>
      </tr>
      <tr>
        <td><span class="style2">Student I/C </span></td>
        <td><span class="style2">:</span></td>
        <td><input name="ic" type="text" id="ic" value="<?php echo $info['stud_ic']; ?>"></td>
      </tr>
      <tr>
        <td><span class="style2">Student Course </span></td>
        <td><span class="style2">:</span></td>
        <td><span class="style2">
          <select name="course" id="course" >
            <?php
			//GET SELECTED COURSE
			$sql_get_course="SELECT * FROM course ORDER BY course_code";
			$get_course=mysql_query($sql_get_course);
			while ($cou=mysql_fetch_assoc($get_course)) {
				$a="";
				if ($info['stud_course']==$cou['course_code'])
				{  $a="selected"; }
				?>
            <option value="<?php echo $cou['course_code']; ?>" <?php echo $a; ?>><?php echo $cou['course_name']; ?></option>
                <?php } ?>
          </select>
        </span> </td>
      </tr>
      <tr>
        <td><span class="style2">Student Semester </span></td>
        <td><span class="style2">:</span></td>
        <td><span class="style2">
          <select name="sem" id="sem">
            <?php 
			//GET SELECTED SEMESTER
			$sql_get_sem="SELECT * FROM semester ORDER BY sem_num";
			$get_sem=mysql_query($sql_get_sem);
			while ($s=mysql_fetch_assoc($get_sem)) {
				$a="";
				if ($info['stud_sem']==$s['sem_num'])
				{	$a="selected";  	}
				?>
            <option value="<?php echo $s['sem_num']; ?>" <?php echo $a; ?>><?php echo $s['sem_num']; ?></option>
            <?php } ?>
          </select>
        </span> </td>
      </tr>
      <tr>
        <td><span class="style2">Student Class </span></td>
        <td><span class="style2">:</span></td>
        <td><span class="style2">
          <select name="class" id="class">
            <?php 
		  	//SELECT THE RIGHT SEMESTER
			$kelas=$info['class'];
			$a="";$b="";$c="";
			if ($kelas=="A") { $a="selected"; }
			else if ($kelas=="B") { $b="selected"; }
			else if ($kelas=="C") { $c="selected"; }
		?>
            <option value="A" <?php echo $a; ?>>A</option>
            <option value="B" <?php echo $b; ?>>B</option>
            <option value="C" <?php echo $c; ?>>C</option>
          </select>
        </span> </td>
      </tr>
      <tr>
        <td><span class="style2">Department</span></td>
        <td><span class="style2">:</span></td>
        <td><span class="style2">
          <select name="dep" id="dep">
            <?php
			$sql_get_dep="SELECT * FROM deparment ORDER BY dep_code";
			$get_dep=mysql_query($sql_get_dep);
			
			while ($row = mysql_fetch_assoc($get_dep)) {
				$a="";
				if ($row['dep_code']==$info['stud_deparment']) {
					$a="selected";
				} ?>
            <option value="<?php echo $row['dep_code']; ?>" <?php echo $a; ?>><?php echo $row['dep_name']; ?></option>
                <?php } ?>
          </select>
        </span> </td>
      </tr>
      <tr>
        <td><span class="style2"></span></td>
        <td><span class="style2"></span></td>
        <td><span class="style2"></span></td>
      </tr>
      <tr>
        <td colspan="3"><div align="center">
          <input name="save" type="submit" id="save" value="Save">
        </div></td>
        </tr>
	</table>
	  </form></td>
  </tr>
</table>
<br>
<?php require_once ("footer.php"); ?>
